// Bristleback plugin - Copyright (c) 2010 bristleback.googlecode.com
// ---------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
// This library is distributed in the hope that it will be useful,
// but without any warranty; without even the implied warranty of merchantability
// or fitness for a particular purpose.
// You should have received a copy of the GNU Lesser General Public License along
// with this program; if not, see <http://www.gnu.org/licenses/lgpl.html>.
// ---------------------------------------------------------------------------
package pl.bristleback.server.bristle.actions;

import org.apache.log4j.Logger;
import org.jwebsocket.api.WebSocketConnector;
import org.jwebsocket.token.Token;
import pl.bristleback.server.bristle.binding.ObjectBinder;
import pl.bristleback.server.bristle.exceptions.BristleRuntimeException;
import pl.bristleback.server.bristle.exceptions.handlers.MissingRightsErrorHandler;
import pl.bristleback.server.bristle.utils.ActionClassElement;

import java.util.List;
import java.util.Set;

/**
 * This class encapsulates all information about action class.
 * <p/>
 * Created on: 2010-09-03 16:03:49 <br/>
 *
 * @author Wojciech Niemiec
 */
public final class RemoteActionInformation {
  private static Logger log = Logger.getLogger(RemoteActionInformation.class.getName());

  private String actionName;
  private Set<String> requiredRights;
  private RemoteAction action;
  private Class<? extends RemoteAction> actionClass;
  private List<ActionClassElement> tokenizerWrappers;
  private List<ActionClassElement<ObjectBinder>> binders;

  private boolean actionHandlingErrors;
  private boolean singleton = true;

  public void handleMissingRightsError(WebSocketConnector connector, Token token) {
    if (!actionHandlingErrors) {
      throw new BristleRuntimeException("Action with name " + actionName + " cannot handle missing rights error");
    }
    ((MissingRightsErrorHandler) action).handleMissingRightsError(requiredRights, connector, token);
  }

  public String getActionName() {
    return actionName;
  }

  public RemoteAction getAction() {
    return action;
  }

  public Class<? extends RemoteAction> getActionClass() {
    return actionClass;
  }

  public void setActionClass(Class<? extends RemoteAction> actionClass) {
    this.actionClass = actionClass;
  }

  public Set<String> getRequiredRights() {
    return requiredRights;
  }

  public void setActionName(String actionName) {
    this.actionName = actionName;
  }

  public void setRequiredRights(Set<String> requiredRights) {
    this.requiredRights = requiredRights;
  }

  public void setAction(RemoteAction action) {
    this.action = action;
  }

  public boolean isActionHandlingErrors() {
    return actionHandlingErrors;
  }

  public void setActionHandlingErrors(boolean actionHandlingErrors) {
    this.actionHandlingErrors = actionHandlingErrors;
  }

  public List<ActionClassElement> getTokenizerWrappers() {
    return tokenizerWrappers;
  }

  public void setTokenizerWrappers(List<ActionClassElement> tokenizerWrappers) {
    this.tokenizerWrappers = tokenizerWrappers;
  }

  public List<ActionClassElement<ObjectBinder>> getBinders() {
    return binders;
  }

  public void setBinders(List<ActionClassElement<ObjectBinder>> binders) {
    this.binders = binders;
  }

  public boolean isSingleton() {
    return singleton;
  }

  public void setSingleton(boolean singleton) {
    this.singleton = singleton;
  }
}
